package com.reds.backend.controller.adminController;

import com.alibaba.fastjson2.JSONObject;
import com.reds.backend.utils.adminUtils.admin.StpAdminUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.reds.backend.service.admin.adminCheckService;

import java.util.Map;

@RestController
@RequestMapping("/adminCheck")
public class adminCheckController {
    @Autowired
    adminCheckService adminCheckService;
    @PostMapping("/getAdminList/")
    public JSONObject getAdminList(@RequestParam Map<String,String> map){
        StpAdminUtil.checkRoleOr("admin","superAdmin");
        return adminCheckService.getAllAdmin(Integer.parseInt(map.get("sizes")),Integer.parseInt(map.get("page")),map.get("role"));
    }
    @PostMapping("/changeAdminRole/")
    public String changeAdminRole(@RequestParam Map<String,String> map){
        StpAdminUtil.checkRole("superAdmin");
        return adminCheckService.changeAdminRole(Integer.parseInt(map.get("id")),map.get("role"));
    }
}
